#include "StdAfx.h"
#include "Locator.h"
#include "SoundBank.h"
#include "VocoderController.h"
#include "ModulatorStream.h"
#include "ModulatorThread.h"
#include "CarrierStream.h"
#include "VocoderStream.h"
#include "SampleBuffer.h"
#include "VocoderThread.h"
#include "PitchTracker.h"
#include "ModulatorTextProvider.h"
#include "Recorder.h"
#include "Settings.h"

static Locator* locator = NULL;

Locator* Locator::Instance()
{
	if(locator==NULL)
	{
		locator = new Locator();
	}
	return locator;
}

Locator::Locator(void)
{
	soundBank = NULL;
	controller = NULL;
	modulatorStream = NULL;
	modulatorThread = NULL;
	carrierStream = NULL;
	vocoderStream = NULL;
	modulatorBuffer = NULL;
	vocoderBuffer = NULL;
	vocoderThread = NULL;
	outputStream = NULL;
	pitchTracker = NULL;
	textProvider = NULL;
	recorder = NULL;
	settings = NULL;
	settingsProvider = NULL;
}

Locator::~Locator(void)
{
	if(soundBank!=NULL) delete soundBank;
	if(controller!=NULL) delete controller;
	if(settingsProvider!=NULL) delete settingsProvider;
	if(modulatorStream!=NULL) delete modulatorStream;
	if(modulatorThread!=NULL) delete modulatorThread;
	if(carrierStream!=NULL) delete carrierStream;
	if(vocoderStream!=NULL) delete vocoderStream;
	if(modulatorBuffer!=NULL) delete modulatorBuffer;
	if(vocoderBuffer!=NULL) delete vocoderBuffer;
	if(vocoderThread!=NULL) delete vocoderThread;
	if(pitchTracker!=NULL) delete pitchTracker;
	if(textProvider!=NULL) delete textProvider;
	if(recorder!=NULL) delete recorder;
	if(settings!=NULL) delete settings;
}

VocoderController* Locator::GetController(){return controller;}
void Locator::SetController(VocoderController* c){controller=c;}

SoundBank* Locator::GetSoundBank(){return soundBank;}
void Locator::SetSoundBank(SoundBank* s){soundBank=s;}

SettingsProvider* Locator::GetSettingsProvider(){return settingsProvider;}
void Locator::SetSettingsProvider(SettingsProvider* s){settingsProvider=s;}

void Locator::SetModulatorStream(ModulatorStream* modulatorStream){this->modulatorStream=modulatorStream;}
ModulatorStream* Locator::GetModulatorStream(){return modulatorStream;}

void Locator::SetModulatorThread(ModulatorThread* modulatorThread){this->modulatorThread=modulatorThread;}
ModulatorThread* Locator::GetModulatorThread(){return modulatorThread;}

void Locator::SetCarrierStream(CarrierStream* carrierStream){this->carrierStream=carrierStream;}
CarrierStream* Locator::GetCarrierStream(){return carrierStream;}

void Locator::SetVocoderStream(VocoderStream* vocoderStream){this->vocoderStream=vocoderStream;}
VocoderStream* Locator::GetVocoderStream(){return vocoderStream;}

void Locator::SetModulatorBuffer(SampleBuffer2* modulatorBuffer){this->modulatorBuffer=modulatorBuffer;}
SampleBuffer2* Locator::GetModulatorBuffer(){return modulatorBuffer;}

void Locator::SetVocoderBuffer(SampleBuffer* vocoderBuffer){this->vocoderBuffer=vocoderBuffer;}
SampleBuffer* Locator::GetVocoderBuffer(){return vocoderBuffer;}

void Locator::SetVocoderThread(VocoderThread* vocoderThread){this->vocoderThread=vocoderThread;}
VocoderThread* Locator::GetVocoderThread(){return vocoderThread;}

void Locator::SetOutputStream(sf::SoundStream* outputStream){this->outputStream=outputStream;}
sf::SoundStream* Locator::GetOutputStream(){return outputStream;}

void Locator::SetPitchTracker(PitchTracker* p)
{
	if(this->pitchTracker) delete this->pitchTracker;
	this->pitchTracker=p;
}
PitchTracker* Locator::GetPitchTracker(){return pitchTracker;}

void Locator::SetModulatorTextProvider(ModulatorTextProvider* textProvider){this->textProvider=textProvider;}
ModulatorTextProvider* Locator::GetModulatorTextProvider(){return textProvider;}

void Locator::SetRecorder(Recorder* recorder){this->recorder=recorder;}
Recorder* Locator::GetRecorder(){return recorder;}

void Locator::SetSettings(Settings* settings){this->settings=settings;}
Settings* Locator::GetSettings(){return settings;}